package conf

import (
	"time"
	"utilx/dbx"
)

type ServerConf struct {
	Name      string                  `json:"name" toml:"name"`
	Port      int                     `json:"port" toml:"port"`
	Debug     bool                    `json:"debug" toml:"debug"`       //deug
	Auth      bool                    `json:"auth" toml:"auth"`         // 验证jwt
	DataBase  map[string]dbx.DataBase `json:"database" toml:"database"` //数据库配置
	JWTConfig JWTConfig               `json:"jwt" toml:"jwt"`           //jwt 配之
}
type JWTConfig struct {
	Expire     int    `json:"expire" toml:"expire"`           //国企时间 1
	Unit       string `json:"unit" toml:"unit"`               // 时间单位  min
	SigningKey string `json:"signing_key" toml:"signing_key"` // 密钥: 钥匙
}

func (r *JWTConfig) Duration() time.Duration {
	if r.Expire == 0 {
		r.Expire = 30
	}
	switch r.Unit {
	case "ss":
		return time.Second * time.Duration(r.Expire)
	case "mm":
		return time.Minute * time.Duration(r.Expire)
	case "hh":
		return time.Hour * time.Duration(r.Expire)
	case "DD":
		return 24 * time.Hour * time.Duration(r.Expire)
	case "MM":
		return 30 * 24 * time.Hour * time.Duration(r.Expire)
	default:
		return time.Minute * time.Duration(r.Expire)
	}
}
